<?php
/*
 * Copyright (c) 2021.  Liuhongbin All rights reserved.
 * @domain http://dkyx.cc
 * @author liuhongbin <514660094@qq.com>
 */

namespace app\common\model\system;

use app\common\model\BaseModel;

class Menu extends BaseModel
{
    /**
     * 主键
     * @var string
     */
    protected $pk = 'id';

    /**
     * 模型名称
     * @var string
     */
    protected $name = 'menu';

    /**
     * 隐藏属性
     * @var array
     */
    protected $hidden = [

    ];

    /**
     * 只读属性
     * @var array
     */
    protected $readonly = [

    ];

    /**
     * 字段类型或者格式转换
     * @var array
     */
    protected $type = [
        'pid' => 'int',
    ];

    /**
     * 定义全局的查询范围
     * @var string[]
     */
    protected $globalScope = [
        "IsDelete"
    ];

    /**
     * 过滤被删除的用户
     * @param $query
     */
    public function scopeIsDelete($query)
    {
        $query->where('is_delete', '=', 0);
    }

    public function getAuthRoles($ids)
    {
        $authMark = $this->whereIn('id', $ids)->where(['menu_type' => 1])->column('auth_mark');
        $res = [];
        foreach ($authMark as $key => $value) {
            $res[] = $value;
        }
        return $res;
    }

    public function setPidAttr($value)
    {
        return intval($value);
    }
}
